/**
 * 题目1
 */
trait TrafficLights{

    fn red(&self) -> i32;
    fn yellow(&self) ->i32;
    fn green(&self) ->i32;
}

struct Led {}
impl TrafficLights for Led{
    fn red(&self) ->i32 {
        return 10;
    }

    fn yellow(&self) ->i32 {
        return 20;
    }

    fn green(&self) ->i32{
        return 30;
    }
}


/**
 * 题目二
 */

fn calculation(parm:Vec<u32> ) ->Option<u32> {
    let  mut value:u32 = 0;
    for i in & parm{
        value = value + i;
    }
    return Option::Some(value);
}
/**
 * 题目三
 */

 enum Type {
    triangle,circular,square
 }

 struct Point<T> {
     x:T,
     y:T,
     p:Type
 }
 
fn area(parm:Point<f64>) ->f64{
    match parm.p{
        //三角形
        Type::triangle =>{
            return parm.x*parm.y/2.0;
        }

        //圆
        Type::circular =>{
            return 3.14 * parm.x*parm.x;
        }
        //矩形
        Type::square =>{
            return parm.x*parm.y;
        }
    }
}


fn main() {
    let entity = Led {};
    println!("{},{},{}",entity.red(),entity.yellow(),entity.green()); 
    
    let mut vector = vec![1,2,3];
    let opt:Option<u32> = calculation(vector);
    match opt {
        Option::Some(something) => {
            println!("{}", something);
        },        Option::None => {
            println!("opt is nothing");
     
        }
    }

    let v1 = area(Point{x:3.0,y:4.0,p:Type::triangle});
    let v2 = area(Point{x:3.0,y:4.0,p:Type::circular});
    let v3 = area(Point{x:3.0,y:4.0,p:Type::square});
    println!("{},{},{}",v1,v2,v3);
}
